
package panels;

import core.COINCOMOComponent;
import java.awt.BorderLayout;
import java.text.DecimalFormat;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import main.GlobalMethods;

/**
 *
 * @author Raed Shomali
 */
public class COPSEMOPanel extends JPanel
{
    JSplitPane splitPane = new JSplitPane();

    public static COPSEMOGraphPanel graph = new COPSEMOGraphPanel();

    public static COPSEMOParametersPanel parameters = new COPSEMOParametersPanel();

    public static DecimalFormat format2Decimals = new DecimalFormat( "0.00" );
    
    public static COINCOMOComponent component ;
    
    public COPSEMOPanel()
    {
        // Split Pane
        splitPane.setOrientation( JSplitPane.VERTICAL_SPLIT );

        splitPane.setTopComponent( new JScrollPane( parameters ) );
        splitPane.setBottomComponent( new JScrollPane( graph ) );

        splitPane.setDividerLocation( 180 );

        // Refreshes Automatically As You Move the Divider
        splitPane.setContinuousLayout( true );

        // GUI
        this.setLayout( new BorderLayout() );
        this.add( splitPane );
    }

    /**
     * 
     * @param component used to update the COPSEMO Graph
     */
    public void updateCOPSEMO( COINCOMOComponent component )
    {
        COPSEMOPanel.component = component ;
        
        parameters.setInceptionEffortPercentage( component.getInceptionEffortPercentage() ) ;
        parameters.setInceptionSchedulePercentage( component.getInceptionSchedulePercentage() ) ;
        parameters.setElaborationEffortPercentage( component.getElaborationEffortPercentage() ) ;
        parameters.setElaborationSchedulePercentage( component.getElaborationSchedulePercentage() ) ;
        parameters.setConstructionEffortPercentage( component.getConstructionEffortPercentage() ) ;
        parameters.setConstructionSchedulePercentage( component.getConstructionSchedulePercentage() ) ;
        parameters.setTransitionEffortPercentage( component.getTransitionEffortPercentage() ) ;
        parameters.setTransitionSchedulePercentage( component.getTransitionSchedulePercentage() ) ;
        
        parameters.setInceptionPM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getInceptionPM() , 2  ) ) ) ; 
        parameters.setElaborationPM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getElaborationPM() , 2  ) ) ) ; 
        parameters.setConstructionPM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getConstructionPM() , 2  ) ) ) ; 
        parameters.setTransitionPM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getTransitionPM() , 2  ) ) ) ; 
        parameters.setECTotalPM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getPMTotalEC() , 2  ) ) ) ; 
        parameters.setTotalPM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getPMTotal() , 2  ) ) ) ; 
        
        parameters.setInceptionM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getInceptionM() , 2  ) ) ) ; 
        parameters.setElaborationM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getElaborationM() , 2  ) ) ) ; 
        parameters.setConstructionM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getConstructionM() , 2  ) ) ) ; 
        parameters.setTransitionM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getTransitionM() , 2  ) ) ) ; 
        parameters.setECTotalM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getMTotalEC() , 2  ) ) ) ; 
        parameters.setTotalM( format2Decimals.format( GlobalMethods.roundOff( (float) component.getMTotal() , 2  ) ) ) ; 
        
        parameters.setInceptionP( format2Decimals.format( GlobalMethods.roundOff( (float) component.getInceptionP() , 2  ) ) ) ; 
        parameters.setElaborationP( format2Decimals.format( GlobalMethods.roundOff( (float) component.getElaborationP() , 2  ) ) ) ; 
        parameters.setConstructionP( format2Decimals.format( GlobalMethods.roundOff( (float) component.getConstructionP() , 2  ) ) ) ; 
        parameters.setTransitionP( format2Decimals.format( GlobalMethods.roundOff( (float) component.getTransitionP() , 2  ) ) ) ; 
        parameters.setECTotalP( format2Decimals.format( GlobalMethods.roundOff( (float) component.getPTotalEC() , 2  ) ) ) ; 
        parameters.setTotalP( format2Decimals.format( GlobalMethods.roundOff( (float) component.getPTotal() , 2  ) ) ) ; 
        
        parameters.setECTotalEffort( format2Decimals.format( GlobalMethods.roundOff( (float) component.getPMTotalEC(), 2  ) ) );
        parameters.setECTotalSchedule( format2Decimals.format( GlobalMethods.roundOff( (float) component.getMTotalEC(), 2  ) ) );
        parameters.setTotalEffort( format2Decimals.format( GlobalMethods.roundOff( (float) component.getPMTotal(), 2  ) ) );
        parameters.setTotalSchedule( format2Decimals.format( GlobalMethods.roundOff( (float) component.getMTotal(), 2  ) ) );
        
        graph.setInceptionPersonnel( component.getInceptionP() );
        graph.setInceptionMonths( component.getInceptionM() );

        graph.setElaborationPersonnel( component.getElaborationP() );
        graph.setElaborationMonths( component.getElaborationM() );

        graph.setConstructionPersonnel( component.getConstructionP() );
        graph.setConstructionMonths( component.getConstructionM() );

        graph.setTransitionPersonnel( component.getTransitionP() );
        graph.setTransitionMonths( component.getTransitionM() );
        
        graph.repaint();
    }

}
